<template>
	<om-formsub-outer :index="index" :checkedit="checkedit">
		<om-autoform @deleteItem="deleteUserItem" ref="autoform" :initConfigData="autoformdata" :initValue="initValue"></om-autoform>
	</om-formsub-outer>
</template>

<script>
	import {buildSubFormData, subOnLoad, changeEditor,configSelectData,hasValue} from '@/static/js/formUtil.js';
	import { ignoreHtml,ptFloat,minusF,getDateStr,errorModal} from '@/static/js/common.js';
	import urlUtil from '@/static/js/urlUtil.js'
	export default {
		provide() {
			return {
				formPage: this
			};
		},
		data() {
			return buildSubFormData({
				userIdCacheKey: 'rps-hggfpj-tsupplierEvaluation-title4-userIdCacheKey',
			})
		},
		methods:{
			initLoad(){
				let _that = this
				let pro1 = _that.om.request('dictSource/loadCombo', { sourceId: 283,categoryId: 5500 });
				Promise.all([pro1]).then(res=>{
					_that.$refs.autoform.changeEditor("title4", "verifyResultCode", "data", configSelectData(res[0],"code","text"))
					_that.$refs.autoform.initSelectIndex("title4", "verifyResultCode")
					_that.$nextTick(function(){
						if(_that.$refs.autoform.formdata.itemTypeCode != "39105"){
							_that.$refs.autoform.changeEditor("title4","actualValue","type","labelbox")
						}
					})
				})
			},
			clearUserId(){
				let _that = this
				_that.$refs.autoform.clear("title4",'userId')
				_that.$refs.autoform.clear("title4",'posId')
				_that.$refs.autoform.clear("title4",'instId')
			},
			onInputScore(num){
				let _that = this
				if(_that.$refs.autoform.formdata.maxScore){
					if(parseFloat(num) > _that.$refs.autoform.formdata.maxScore){
						_that.$refs.autoform.formdata.score = _that.$refs.autoform.formdata.maxScore
					}
				}
			}
		},
		onShow() {
			let _that = this
			if(_that.$refs.autoform){
				uni.getStorage({
					key:_that.userIdCacheKey,
					success:(res)=>{
						if(res.data){
							let d = res.data
							let formdata = _that.$refs.autoform.formdata
							formdata.userId = d.userId
							formdata.userName = d.userName
							formdata.posId = d.posId
							formdata.posName = d.posName
							formdata.instId = d.instId
							formdata.instName = d.instName
							
							_that.$refs.autoform.changeEditor('title4', 'userId', {
								'link': '../../public/pageSearch/pageSearch',
								"linkParam": {
									url:'supplyEvaDict/getUserList',
									namefield: 'userName/posName/instName',
									namesplit:"/",
									other:JSON.stringify({
										itemId: _that.formdata.itemId,
										firstUserId: d.userId,
										firstPosId: d.posId
									}),
									searchfield: "q",
									initload:true,
									cachename: _that.userIdCacheKey,
								}
							});
							
							uni.removeStorage({
								key:_that.userIdCacheKey
							})
						}
					}
				})
			}
		},
		onLoad(e) {
			let _that = this
			subOnLoad(_that, e, function() {
				
				if(e.configDataCacheKey){
					uni.getStorage({
						key: e.configDataCacheKey,
						success: function(res) {
							if(res.data && Object.prototype.toString.call(res.data)==='[object Array]'){
								_that.autoformdata = res.data
								Object.assign(_that.initValue, _that.formdata)
								
								changeEditor('title4', "userId", {
									'link': '../../public/pageSearch/pageSearch',
									"linkParam": {
										url:'supplyEvaDict/getUserList',
										namefield: 'userName/posName/instName',
										namesplit:"/",
										other:JSON.stringify({
											itemId: _that.formdata.itemId,
											firstUserId: _that.formdata.userId,
											firstPosId: _that.formdata.posId
										}),
										searchfield: "q",
										initload:true,
										cachename: _that.userIdCacheKey,
									}
								}, null, _that.autoformdata)
								
								changeEditor(_that.autoformdata[0].editors, "fileList", "fileSaveNameField", "fileSaveName")
								changeEditor(_that.autoformdata[0].editors, "fileList", "uploadUrl", "uploadFileData/uploadInterimFile")
								changeEditor(_that.autoformdata[0].editors, "fileList", "loadUrl", "uploadFileData/getInterimFile")
								changeEditor(_that.autoformdata[0].editors, "fileList", "fileUploadKey", 93)
								if(_that.formdata.fileList) {
									var tempFileList = []
									var fileUrlList = _that.formdata.fileList.map(t=>{
										tempFileList.push(t.fileSaveName)
										return t.fileSaveName
									})
									changeEditor(_that.autoformdata[0].editors, "fileList", "fileUrlList", fileUrlList)
									changeEditor(_that.autoformdata[0].editors, "fileList", "tempFileList", tempFileList)
								}

								_that.initLoad()
								
								}
							}
						})
					}
				})
			}
		}
</script>

<style>
</style>